package com.zhuandaonet.manager.hystrix;

import com.zhuandaonet.common.constant.Code;
import com.zhuandaonet.common.exception.CallFailException;
import com.zhuandaonet.common.exception.ServiceException;
import com.zhuandaonet.manager.api.RoleServiceApi;
import com.zhuandaonet.manager.req.RoleReq;
import com.zhuandaonet.manager.resp.RoleResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RoleServiceHystrix implements RoleServiceApi {
    @Override
    public RoleResp add(RoleReq req) throws ServiceException {
       return getRoleResp("添加角色时调用不到微服务！");
    }

    @Override
    public RoleResp update(RoleReq req) throws ServiceException {
        return getRoleResp("修改角色时调用不到微服务！");
    }

    @Override
    public RoleResp get(String id) throws ServiceException {
        return getRoleResp("获取角色时调用不到微服务！");
    }

    private RoleResp getRoleResp(String msg) {
        log.error(">>>>>> 调用服务失败！");
        CallFailException exception = new CallFailException(Code.Status.INTERNAL_SERVER_ERROR,Code.Error.CALL_FAIL,msg);
        throw exception;
    }
}
